package com.xujl.mvcbind.ui.home.control;

import android.os.Bundle;
import android.view.View;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.xujl.fastlib.base.BaseFragment;
import com.xujl.fastlib.bean.OnDataChange;
import com.xujl.mvcbind.R;
import com.xujl.mvcbind.adapter.provider.ProviderMultiAdapter;
import com.xujl.mvcbind.bean.ProviderMultiEntity;
import com.xujl.mvcbind.ui.home.model.ComplexFragmentModel;
import com.xujl.mvcbind.ui.home.view.ComplexFragmentView;
import com.xujl.mvcbind.util.TimeLog;

import java.util.List;

import androidx.annotation.NonNull;

/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   :
 *     version: 1.0
 * </pre>
 */

public class ComplexFragmentControl extends BaseFragment<ComplexFragmentModel, ComplexFragmentView> implements OnRefreshLoadMoreListener, OnDataChange<List<ProviderMultiEntity>> {
    private ProviderMultiAdapter mAdapter;
    private static final String TAG = "ComplexFragmentControl";

    public static ComplexFragmentControl newInstance () {
        Bundle args = new Bundle();
        ComplexFragmentControl fragment = new ComplexFragmentControl();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void init (Bundle savedInstanceState) {
        mAdapter = new ProviderMultiAdapter(mModel.getDataList());
        mView.setAdapter(mAdapter);
        mView.startRefresh();
    }

    @Override
    public void onLoadMore (@NonNull RefreshLayout refreshLayout) {
        mModel.getRefreshData(this);
    }

    @Override
    public void onRefresh (@NonNull RefreshLayout refreshLayout) {
        mModel.getRefreshData(this);
    }

    @Override
    public void onChange (List<ProviderMultiEntity> data) {
        mView.stopRefresh();
        TimeLog.logStart(TAG);
        mAdapter.notifyDataSetChanged();
        TimeLog.logEnd(TAG);
    }

    @Override
    public void onClick (View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.btn_all:
//                mAdapter.setDiffNewData(mModel.getDataObjectList());
                mAdapter.notifyDataSetChanged();
                break;
            default:

                break;

        }
    }
}
